$(function(){
	var usertype = $('#usertype option:selected').val();//选中的值
	var orderNumber=$("#orderNumber").val();//用户昵称\
	
	//自动加载
	   loadData(usertype,orderNumber,1);
});



function loadData(usertype,orderNumber,pageNo){

	var pageSize = 8 ,html="",id="",realName="",payMoney="",transactionNum="",bankCardName="",gmtDatetime="" ,bankCard="",bankName="",str="",title="",payType="",payTime="",comcateTime="";
		//获取用户信息列表
		$("#thislist").html("");
	  $.ajax({  
        type : "GET",  
        url : urlcore + "/api/orderGoods/getOrderGoodsUserByHouTai?usertype="+usertype+"&orderNumber="+orderNumber+"&pageNum="+pageNo+"&pageSize="+pageSize, 
        dataType : "json",
        headers:{"Content-Type":"application/json;charset=UTF-8"},
        success: function(data) {//data是返回的hash,key之类的值，key是定义的文件名 
        	var da=data.data.list;
        	if(data.success==true){
        		for(var i=0;i<da.length;i++ ){
        			id=da[i].id;
        			orderNumber=da[i].orderNumber;
        			title=da[i].goods.title;
        			realName=da[i].user.realName;
        			nums=da[i].nums;
        			userType=da[i].user.userType==2?"骑手":da[i].user.userType==3?"商家":"用户";
        			payType=da[i].payType;
        			payTime=da[i].payTime;
        			orderStatus=da[i].orderStatus;
        			id=da[i].id;
					var Status;
					if(orderStatus==0){
						Status="未提交订单";
					}else if(orderStatus==1){
						Status="提交未支付";
					}else if(orderStatus==2){
						Status="支付失败";
					}else if(orderStatus==3){
						Status="支付成功";
					}else if(orderStatus==4){
						Status="已发货";
					}else if(orderStatus==5){
						Status="订单取消";
					}else if(orderStatus==6){
						Status="订单删除";
					}else if(orderStatus==7){
						Status="已完成";
					}
        			payMoney=da[i].payMoney;
        			gmtDatetime=da[i].gmtDatetime;
          html += '<tr class="footable-even" style="display: table-row;">'+
                '	<td class="footable-visible">'+(i+1)+'</td>'+
            	'	<td class="footable-visible">'+orderNumber+'</td>'+
            	'	<td class="footable-visible">'+title+'</td>'+
				'	<td class="footable-visible">'+userType+'</td>'+
				'	<td class="footable-visible">'+realName+'</td>'+
				'	<td class="footable-visible">'+nums+'</td>'+
				'	<td class="footable-visible">'+Status+'</td>'+
				'	<td class="footable-visible" id="deal">'+
			     "   \t\t\t<a class=\"btn btn-primary btn-xs\" href=\"goodsorder_detail.html?id="+id+"&type="+da[i].user.userType+"\"> 详细</a>\n" + 
			     "   \t\t\t<a class=\"btn btn-primary btn-xs\"  href=\"javascript:;\" onclick=\"sendGoods("+id+","+orderStatus+")\">发货</a>\n" + 
			    "   \t\t\t<a class=\"btn btn-primary btn-xs\"  href=\"javascript:;\" onclick=\"deleteOrderGoods("+id+","+orderStatus+")\">删除</a>\n" + 
                '  </td>'+
				'</tr>';
        		}
        		$("#thislist").append(html);
        		$('#thiscount').text(data.data.total);
        		$("#pager").pager({
					pagenumber: pageNo, 
					pagecount:data.data.pages,
					totalcount:data.data.total,
					buttonClickCallback: PageClick
				}); 
            }
        },
        error:function(){  
            alert("失败");  
        }  
    }); 
	
}

function sendGoods(id,status){
	   if(status!=3){
	   	alert("此订单不符合发货条件！");
	   	return false;
	   }
    	   $.ajax({  
	        type : "POST",  
	        url : urlcore + "/api/orderGoods/sendGoods?orderGoodsId="+id, 
	        dataType : "json",
	        headers:{"Content-Type":"application/json;charset=UTF-8"},
	        data : {},
	        success: function(data) {//data是返回的hash,key之类的值，key是定义的文件名 
	        	if(data.success==true){
	        		location.reload();
	        	}else {
	                alert(data.msg);
	            }
	        },
	        error:function(){  
	            alert("上传失败");  
	        }  
    }); 
	
}

 function deleteOrderGoods(id){
 	  if (confirm("确定要删除此订单吗？")) {
			$.ajax({  
	        type : "POST",  
	        url : urlcore + "/api/orderGoods/deleteOrderGoods?orderGoodsId="+ id,
	        dataType : "json",
	        headers:{"Content-Type":"application/json;charset=UTF-8"},
	        data : {},
	        success: function(data) {//data是返回的hash,key之类的值，key是定义的文件名 
	        	if(data.success==true){
	        		location.reload();
	        	}else {
	                alert(data.msg);
	            }
	        },
	        error:function(){  
	            alert("上传失败");  
	        }  
    }); 
 
    } else {
      return;
    }

 }


//回调函数  
	PageClick = function(pageclickednumber) {  
		var usertype = $('#usertype option:selected') .val();//选中的值
		var orderNumber=$("#orderNumber").val();//用户昵称
	    loadData(usertype,orderNumber,pageclickednumber);
	}
	



//搜索
function searchuser() {
		var usertype = $('#usertype option:selected') .val();//选中的值
		var orderNumber=$("#orderNumber").val();//用户昵称
	    loadData(usertype,orderNumber,1);
}

//搜索
function search() {
		var usertype = $('#usertype option:selected') .val();//选中的值
		var orderNumber=$("#goods").val();//用户昵称
	    loadData(usertype,orderNumber,1);
}